using System.Collections.Generic;
using NHibernate.Validator;
using SharpArch.Core.PersistenceSupport;
using SharpArch.Core.DomainModel;
using System;

namespace MindMelder.Core
{
    public class User : Entity
    {
        public User()
        {
			FirstName = string.Empty;
			LastName = string.Empty;
        	Country = string.Empty;
        	State = string.Empty;
			BirthDate = new DateTime(1800, 1, 1);
        	OpenId = string.Empty;
        }

		[NotNull, NotEmpty]
		public virtual string FirstName { get; set; }

		[NotNull, NotEmpty]
		public virtual string LastName { get; set; }

		[NotNull, NotEmpty]
		public virtual string Country { get; set; }

		[NotNull, NotEmpty]
		public virtual string State { get; set; }

    	public virtual string Location
    	{
    		get
    		{
				if (string.IsNullOrEmpty(Country) && string.IsNullOrEmpty(State))
				{
					return "(unkown)";
				}
    			return string.IsNullOrEmpty(Country) ? State : State + ", " + Country;
    		}
    	}

		public virtual DateTime BirthDate { get; set; }

		[DomainSignature]
		[NotNull, NotEmpty]
		public virtual string OpenId { get; set; }

		public virtual IList<Skill> Skills { get; set; }

		public virtual IList<Message> Messages { get; set; }

    	public virtual string FullName
    	{
    		get
    		{
    			return FirstName + " " + LastName;
    		}
    	}

    	public virtual int Age
    	{
    		get
    		{
				DateTime now = DateTime.Now;
				int age = now.Year - BirthDate.Year;
				if (now < BirthDate.AddYears(age)) age--;
    			return age;
    		}
    	}

    	public virtual string DisplayAge
    	{
    		get
    		{
    			if (BirthDate == new DateTime(1800, 1,1))
    			{
    				return "(unknown)";
    			}
    			return Age.ToString();
    		}
    	}
    }
}